using AutoMapper;
using Pay.DTO;
using Pay.Data;
using Pay.IService;
using Pay.Core;

namespace Pay.Service.AutoMapper
{
    public class ProductActivityMapper : IStartupDto
    {
        private IMapperConfigurationExpression _cfg;
        public ProductActivityMapper(IMapperConfigurationExpression cfg)
        {
            _cfg = cfg;
        }
        public void Execute()
        {
            Create();
        }
        protected virtual void Create()
        {
            _cfg.CreateMap<ProductActivity, product_activity_dto>()
                .ForMember(dest => dest.id, src => src.MapFrom(c => c.Id))
                .ForMember(dest => dest.product_id, src => src.MapFrom(c => c.ProductId))
                .ForMember(dest => dest.product_sku_id, src => src.MapFrom(c => c.ProductSkuId))
                .ForMember(dest => dest.activity_id, src => src.MapFrom(c => c.ActivityId))
                .ForMember(dest => dest.activity_price, src => src.MapFrom(c => c.ActivityPrice))
                .ForMember(dest => dest.activity_red_drill, src => src.MapFrom(c => c.ActivityRedDrill))
                .ForMember(dest => dest.activity_stock, src => src.MapFrom(c => c.ActivityStock))
                .ForMember(dest => dest.create_time, src => src.MapFrom(c => c.CreateTime.ToDateTime()))
                .ForMember(dest => dest.is_sold_out, src => src.MapFrom(c => c.IsSoldOut))
                .ForMember(dest => dest.sale_count, src => src.MapFrom(c => c.SaleCount))
                .ForMember(dest => dest.top, src => src.MapFrom(c => c.Top))
                .ForMember(dest => dest.activity, src => src.MapFrom(c => c.Activity))
                .ForMember(dest => dest.product, src => src.MapFrom(c => c.Product))
                .ForMember(dest => dest.product_sku, src => src.MapFrom(c => c.ProductSku))
                .ForMember(dest => dest.product_activity_time_buy, src => src.MapFrom(c => c.ProductActivityTimeBuy));


            _cfg.CreateMap<product_activity_dto, ProductActivity>()
                .ForMember(dest => dest.Id, src => src.MapFrom(c => c.id))
                .ForMember(dest => dest.ProductId, src => src.MapFrom(c => c.product_id))
                .ForMember(dest => dest.ProductSkuId, src => src.MapFrom(c => c.product_sku_id))
                .ForMember(dest => dest.ActivityId, src => src.MapFrom(c => c.activity_id))
                .ForMember(dest => dest.ActivityPrice, src => src.MapFrom(c => c.activity_price))
                .ForMember(dest => dest.ActivityRedDrill, src => src.MapFrom(c => c.activity_red_drill))
                .ForMember(dest => dest.ActivityStock, src => src.MapFrom(c => c.activity_stock))
                .ForMember(dest => dest.CreateTime, src => src.MapFrom(c => c.create_time.ToUnix()))
                .ForMember(dest => dest.IsSoldOut, src => src.MapFrom(c => c.is_sold_out))
                .ForMember(dest => dest.SaleCount, src => src.MapFrom(c => c.sale_count))
                .ForMember(dest => dest.Top, src => src.MapFrom(c => c.top))
                .ForMember(dest => dest.Activity, src => src.MapFrom(c => c.activity))
                .ForMember(dest => dest.Product, src => src.MapFrom(c => c.product))
                .ForMember(dest => dest.ProductSku, src => src.MapFrom(c => c.product_sku))
                .ForMember(dest => dest.ProductActivityTimeBuy, src => src.MapFrom(c => c.product_activity_time_buy));


        }
    }
}
